| Conditions | 3 |
| Total Lines | 31 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { currentTranslations } from '../../language'; |
||
| 23 | |||
| 24 | function showToast(message: string): void { |
||
| 25 | const existingToast = document.getElementById('toast-notification'); |
||
| 26 | if (existingToast) { |
||
| 27 | existingToast.remove(); |
||
| 28 | } |
||
| 29 | |||
| 30 | if (toastTimeout) { |
||
| 31 | clearTimeout(toastTimeout); |
||
| 32 | } |
||
| 33 | |||
| 34 | const toast = document.createElement('div'); |
||
| 35 | toast.id = 'toast-notification'; |
||
| 36 | toast.className = 'toast'; |
||
| 37 | toast.textContent = message; |
||
| 38 | toast.setAttribute('role', 'alert'); |
||
| 39 | toast.setAttribute('aria-live', 'polite'); |
||
| 40 | |||
| 41 | document.body.appendChild(toast); |
||
| 42 | |||
| 43 | // Use setTimeout instead of requestAnimationFrame for better testability |
||
| 44 | setTimeout(() => { |
||
| 45 | toast.classList.add('show'); |
||
| 46 | }, 0); |
||
| 47 | |||
| 48 | toastTimeout = setTimeout(() => { |
||
| 49 | toast.classList.remove('show'); |
||
| 50 | setTimeout(() => { |
||
| 51 | toast.remove(); |
||
| 52 | }, 300); // Wait for fade out animation |
||
| 53 | }, 3000); |
||
| 54 | } |
||
| 55 |